<template>
	<view>
		<Navbar :backUrl="backUrl"></Navbar>
		<view class="u-m-l-30 u-m-t-30 u-m-r-30 u-position-relative" v-if="bannerList[0]">
			<swiper class="swiper_box" :circular="true" :current="swiperCurrent" @change="swiperChange">
				<swiper-item v-for="(item,index) in bannerList" :key="item.id">
					<u-image width="100%" height="350rpx" border-radius="20" mode="aspectFit" :src="item.url"
						@click="openSwiper(index)"></u-image>
				</swiper-item>
			</swiper>
			<view class="swiper_type_box">
				<view class="swiper_type" :class="item.check ? 'check' : ''" v-for="item in bannerTypeList"
					:key="item.name" @click="clickSwiper(item)">{{item.name}}</view>
			</view>
		</view>
		<!-- 个人详情 -->
		<Info :isPromoter="isPromoter" :data="teaData"></Info>
		<!-- 报名用户工具栏 -->
		<Tool @useTool="toUseTool" :data="teaData.info.user_status"></Tool>
		<!-- 通用工具栏 -->
		<view :style="stickyStyle">
			<CommonTool ref="Tool" :data="teaData" :isPromoter="isPromoter" :toolList="toolList" :toolShow="toolShow"
				@previewPoster="previewPoster" @openTool="openTool"></CommonTool>
		</view>
		<u-tabs-swiper :current="current" :list="tabList" :is-scroll="false" bg-color="transparent"
			active-color="#B3723E" @change="tabChange"></u-tabs-swiper>
		<!-- 青创私董信息组件 -->
		<Content :data="teaData" :badgeData="badgeData" :poster="poster" :isPromoter="isPromoter"
			@goTeaPersonDetail="goTeaPersonDetail" @addPerson="addPerson" @callMobile="callMobile"
			@previewPoster="previewPoster" @openTool="openTool" @chooseThank="chooseThank"
			@switchThanksList="switchThanksList" @viewDonateImage="viewDonateImage" v-if="current == 0">
		</Content>
		<!-- 来友列表组件 -->
		<TeaPerson :list="teaFriendList" :isPromoter="isPromoter" @goTeaPersonDetail="goTeaPersonDetail"
			@callMobile="callMobile" @examine="getExamine" @refuse="getRefuse" @process="getProcess" v-else></TeaPerson>
		<view style="height: 600rpx;"></view>

		<view class="bottom_box">
			<view class="bottom_btn_box">
				<view class="u-flex u-width-100">
					<view class="u-flex-1 bottom_btn"
						:class="[0,bottomList.length].includes(index) ? '' : 'u-m-l-10 u-m-r-10'"
						:style="{background: item.bgColor}" v-for="(item,index) in bottomList" :key="item.id"
						@click="handleClick(item.click)">{{item.name}}</view>
				</view>
			</view>
		</view>

		<!-- 图片预览组件 -->
		<PositerImage :data="poster" @closePosterImage="poster.show = false"></PositerImage>

		<!-- 视频播放组件-->
		<TeaVideo :show="video.show" :src="video.url" :time="video.time" @close="video.show = false"></TeaVideo>

		<!-- 朋友圈分享引导 -->
		<u-popup v-model="moment.show" mode="center" border-radius="20" width="600rpx" :closeable="true"
			:close-icon-color="'#fff'" @close="moment.show = false">
			<view>
				<u-image :src="moment.image" width="100%" mode="widthFix"></u-image>
			</view>
		</u-popup>

		<!-- 礼物感谢框 -->
		<GiftPopup :show="giftShow" :status="giftBtnStatus" :data="gift" @onCloseGift="onGiftClose"
			@onGiftChoose="onGiftChoose"></GiftPopup>

		<!-- 通用提示框 -->
		<Modal :show="modal.show" :confirmText="modal.confirm" :cancelText="modal.cancel" :modalContent="modal.content"
			:showCancel="modal.showCancel" :maskAble="modal.maskAble" @confirm="modalConfirm" @cancel="modalCancel"
			@modeClose="modeClose"></Modal>

		<!-- 捐赠二维码 -->
		<DonatePopup :popupShow="donateData.show" :url="donateData.url" @popupClose="donateData.show = false">
		</DonatePopup>

		<!-- 分享组件 -->
		<Share :isShowShare="shareShow" :isMoment="true" @closeShare="closeShare" @handleOpenMoment="openMoment">
		</Share>
	</view>
</template>

<script>
	import Navbar from '@/components/Navbar.vue'
	import Info from './component/Info.vue'
	import Tool from './component/Tool.vue'
	import CommonTool from './component/CommonTool.vue'
	import Content from './component/Content.vue'
	import TeaPerson from './component/TeaPerson.vue'
	import TeaVideo from './component/TeaVideo.vue'
	import Modal from '@/components/Modal.vue'
	import PositerImage from '@/components/PosterImage.vue'
	import DonatePopup from '@/components/DonatePopup.vue'
	import GiftPopup from '../components/GiftPopup.vue'
	import Share from '@/teaBureau/components/Share.vue'
	import {
		teaDetail,
		teaFriend,
		teaSignCode,
		teaEnd,
		teaPlay,
		teaApply,
		teaQrcode,
		teaRefuse,
		teaCheckSign,
		teaAuditRefuse,
		teaOrderSn,
		teaCreateOrder,
		teaWithdraw
	} from '@/network/tea.js'
	import {
		userInfo,
		singleIntegral,
		businessCardApply,
		getShare,
		bindUserId,
		giftList,
		userGiveGift,
		getConfigInfo,
		userHonorList
	} from '@/network/api.js'
	import {
		TeaBtnList,
		PresidentLevel,
    TeaStatus,
		formatContent,
		call,
		presidentClass,
		InitScene,
		generateUUID,
		pointTransform
	} from '@/utils/index.js'
	import share from '@/mixins/share.js'
	export default {
		mixins: [share],
		components: {
			Navbar,
			Info,
			Tool,
			CommonTool,
			Content,
			TeaPerson,
			TeaVideo,
			Modal,
			PositerImage,
			Share,
			DonatePopup,
			GiftPopup
		},
		data() {
			return {
				timeOut: null,
				swiperCurrent: 0,
				bannerList: [],
				bannerTypeList: [{
					name: '大楼外观',
					type: 'build',
					check: true
				}, {
					name: '场地门头',
					type: 'head',
					check: false
				}, {
					name: '酒局环境',
					type: 'images',
					check: false
				}],
				tabList: [{
						name: '酒局介绍'
					},
					/* {
						name: '同局来友',
						count: 0
					} */
				],
				toolShow: false,
				bottomList: [],
				teaData: {},
				teaFriendList: [],
				tea_id: 0,
				user_id: uni.getStorageSync("user_id"),
				// 用户在系统的状态
				user_status: uni.getStorageSync("user_status"),
				current: 0,
				modal: {
					show: false,
					showCancel: true,
					maskAble: true,
					confirm: '申请',
					cancel: '取消',
					content: ''
				},
				poster: {
					show: false,
					image: '',
					signImage: '' /* 签到二维码 */
				},
				moment: {
					show: false,
					image: ''
				},
				mixinsShare: {
					title: '青创云店',
					path: '',
					imageUrl: '',
					desc: '',
				},
				giftShow: false,
				gift: {
					list: [],
					checkId: 0,
					checkNum: 0,
					text: '',
					isAnonymous: false
				},
				customStyle: {
					height: '120rpx',
					lineHeight: 1.5
				},
				donateData: {
					show: false,
					url: ''
				},
				isPromoter: false, // 判断是否是酒局发起人
				isExchange: false, // 交换名片
				isFinish: false, // 结束酒局
				isUpload: false, // 上传合照
				finishType: 0, // 0正常结束  11未到开始时间强制结束  22签到不满一半强制结束  33酒局时长不符合要求  44未上传合照
				isPlay: false, // 报名酒局
				isPay: false, // 付费报名酒局
				isScore: false, // 酒局评价
				isExamine: false, // 审核报名
				isProcess: false, // 审核取消已报名
				isAuditRefuse: false, // 待审核取消报名
				examine: {}, // 被审核人参数
				isRefuse: false, // 取消报名
				refuse: {}, // 被取消人参数
				inviterId: '', // 酒局邀请人id
				badgeData: {}, // 青创私董徽章
				shareShow: false,
				video: {
					show: false,
					url: '',
					time: 0
				},
				toolList: [{
						id: 0,
						name: '第一步',
						desc: '扫码签到',
						color: '#3366FE',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240914345214253721.png'
					},
					{
						id: 1,
						name: '3分钟',
						desc: '故事计时',
						color: '#A16534',
						url: 'https://weilaijiuju.oss-cn-shenzhen.aliyuncs.com/course/20250625509632525449.mp4',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240821726657758869.png',
						time: 180
					},
					{
						id: 2,
						name: '2分钟',
						desc: '项目计时',
						color: '#A16534',
						url: 'https://weilaijiuju.oss-cn-shenzhen.aliyuncs.com/course/20250625861593846841.mp4',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240821726657758869.png',
						time: 120
					},
					{
						id: 3,
						name: '转换能量',
						desc: '我的推荐',
						color: '#555294',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240914173185594916.png'
					},
					/* {
						id: 4,
						name: '互帮互助',
						desc: '我的任务',
						color: '#555294',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240914536388471923.png'
					}, */
					{
						id: 5,
						name: '酒局复盘',
						desc: '来友评价',
						color: '#555294',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240914937488638131.png'
					},
					/* {
						id: 7,
						name: '国学智慧',
						desc: '智慧人生',
						color: '#555294',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240914937488638131.png'
					}, */
					{
						id: 6,
						name: '酒局合照',
						desc: '上传照片',
						color: '#CF4641',
						image: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20240821336092408961.png'
					}
				],
				giftBtnStatus: true,
				stickyStyle: "",
				backUrl: "",
				// 酒局状态
				tea_status: 0, // 1报名中 3已截止 5已结束 7已失效
				// 用户在该酒局的状态 
				status: 0 // 10未报名 11已报名 12待审核
			}
		},
		async onLoad(options) {
      wx.hideShareMenu()
			await this.$onLaunched
			uni.showLoading()
			if (options.scene) {
				options.inviterId = InitScene(options.scene).inviterId
				options.id = InitScene(options.scene).id
				uni.setStorageSync("inviterUrl",
					`teaBureau/teaDetail/teaDetail?id=${options.id}&inviterId=${options.inviterId}`)
				const pages = getCurrentPages()
				const currentPage = pages[pages.length - 1]
				const params = {
					userid: uni.getStorageSync("user_id"),
					inviter: InitScene(options.scene).inviterId,
					url: currentPage.$page.fullPath || ''
				}
				bindUserId(params)
			}
			if (options.inviterId) {
				this.inviterId = options.inviterId
				this.backUrl = "home"
			}
			this.user_id = uni.getStorageSync("user_id")
			this.user_status = uni.getStorageSync("user_status")
			this.tea_id = options.id
			this.getTeaDetail()
			this.handleGetShare()
			this.getCheckInQrCode()
		},
		onShow() {
			this.user_id = uni.getStorageSync("user_id")
			this.user_status = uni.getStorageSync("user_status")
			if (this.current == 1) {
				this.getTeaPersonList()
			}
		},
		mounted() {
			let _this = this
			uni.$on('update', function() {
				_this.getTeaDetail()
			})
		},
		onUnload() {
			uni.$off('update')
			this.stickyStyle = ''
		},
		onPullDownRefresh() {
			this.timeOut = setTimeout(() => {
				this.getTeaDetail()
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onHide() {
			clearTimeout(this.timeOut)
		},
		onPageScroll(e) {
			if (e.scrollTop > 400) {
				const _this = this
				uni.getSystemInfo({
					success: (res) => {
						const statusBarHeight = res.statusBarHeight || 0;
						const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
						const navBarHeight = menuButtonInfo.height + (menuButtonInfo.top - statusBarHeight) *
							2;
						const stickyTop = statusBarHeight + navBarHeight
						_this.stickyStyle =
							`position:fixed; top:${stickyTop}px;left:0;width:100%;z-index:99998;margin-top:-30rpx`
					}
				})
			} else {
				this.stickyStyle = ''
			}
		},
		methods: {
			tabChange(val) {
				this.current = val
				if (this.current == 1) {
					this.getTeaPersonList()
				}
			},
			handleGetShare() {
				/* 获取分享参数 */
				getShare({
					key: 'teaDetail'
				}).then(res => {
					this.mixinsShare.image = res.data.image
          setTimeout(() => {
          wx.showShareMenu({
              withShareTicket: true,
              menus: ['shareAppMessage', 'shareTimeline']
            })
          }, 1000)
				})
			},
			getTeaDetail() {
				/* 获取酒局详情数据 */
				this.modal.show = false
				const params = {
					user_id: this.user_id,
					tea_id: this.tea_id
				}
				teaDetail(params).then(res => {
					uni.hideLoading()
					res.data.user.president_status = parseInt(res.data.user.president_status)
					res.data.user.president_name = this.getPresidentName(res.data.user.partner_status,res.data.user.president_status)
					res.data.user.president_class = presidentClass(res.data.user.president_status)

					/* 是青创私董或者已经报名 */
					/* if (res.data.info.user_status == 11 || (this.user_id == res.data.user.id)) {
						res.data.info.address = res.data.info.address
					} else {
						res.data.info.address = res.data.info.address.substring(0, res.data.info.address.indexOf(
							"区") + 1)
					} */

					if (res.data.theme) {
						res.data.theme.content = formatContent(res.data.theme.content)
					}
					switch (res.data.info.pay_type) {
						case 1:
							res.data.info.pay_name = '免费'
							break;
						case 2:
							res.data.info.pay_name = `${res.data.info.price}元`
							break;
						case 3:
							res.data.info.pay_name = `${res.data.info.price}积分`
							break;
					}
					res.data.user.number = pointTransform(res.data.user.number)
					this.teaData = res.data
					this.tea_status = res.data.info.tea_status
					this.status = res.data.info.user_status
					this.dealSwiperBanner(res.data.info.image_one, 'build')
					this.dealSwiperBanner(res.data.info.image_two, 'head')
					this.dealSwiperBanner(res.data.info.image_three, 'images')
					if (res.data.info.tea_status !== 7 && (res.data.is_sign == 1 || (this.user_id == res.data.user
							.id))) {
						this.toolShow = true
					}
					if (res.data.info.tea_status == 7) {
						this.toolShow = false
					}
					if (res.data.info.label) {
						res.data.info.label = res.data.info.label.split("#").filter(item => item !== null &&
							item !== undefined && item)
					}
					/* 分享配置 */
					this.mixinsShare.page =
						`/teaBureau/teaDetail/teaDetail?id=${this.tea_id}&inviterId=${uni.getStorageSync("user_id")}`
					this.mixinsShare.title =
						`邀请你参加${res.data.info.start_time.slice(0,10)}在${res.data.info.address}的酒局`

					this.getHonorData(res.data.user.id)
					new Promise((resolve, reject) => {
						this.dealBottomText()
						resolve()
					}).then(() => {
						setTimeout(() => {
							/* if (this.isPromoter == true && res.data.is_evaluate == 1) {
								this.modal.content = '酒局已结束，请为今天的酒局打分，帮助我们下次做得更好'
								this.modal.confirm = '评分'
								this.modal.show = true
								this.isScore = true
							} */
							/* if (this.isPromoter == true && res.data.info.tea_status == 5 && !res.data.image) {
								this.modal.content = '酒局已结束，请为今天的酒局上传合照'
								this.modal.confirm = '确定'
								this.modal.show = true
								this.isUpload = true
							} */
							if (this.isPromoter == false && res.data.is_evaluate == 1 && res.data
								.is_sign == 1) {
								this.modal.content = '酒局已结束，请为今天的酒局打分，帮助我们下次做得更好'
								this.modal.confirm = '评分'
								this.modal.show = true
								this.isScore = true
							}
						}, 200)
					})
				})
			},
			async getHonorData(id) {
				/* 获取青创私董徽章 */
				const params = {
					user_id: id,
					from_user_id: id
				}
				const res = await userHonorList(params)
				res.data.list = res.data.list.slice(0, 4)
				this.badgeData = res.data
			},
			getPresidentName(status1, status2) {
				/* 等级显示 */
				// return PresidentLevel(status)
        return TeaStatus(status1, status2)
			},
			dealBottomText() {
				/* 底部按钮显示 */
				let array = TeaBtnList()
				let bottomList = []
				if (this.user_id == this.teaData.user.id) {
					this.isPromoter = true
					if (this.tabList.length < 2) {
						this.tabList.push({
							name: '同局来友',
							count: 0
						})
					}
					switch (this.tea_status) {
						case 1:
							bottomList = array.filter(item => [0, 1, 3].includes(item.id))
							break;
						case 3:
							bottomList = array.filter(item => [0, 1, 3].includes(item.id))
							break;
						case 5:
							bottomList = array.filter(item => [0, 1, 6].includes(item.id))
							break;
						case 7:
							bottomList = array.filter(item => [0, 1, 8].includes(item.id))
							break;
					}
				} else {
					this.isPromoter = false
					switch (this.tea_status + this.status) {
						case 11:
							bottomList = (this.teaData.end_num == 0 ? array.filter(item => [0, 1, 7].includes(item.id)) :
								array.filter(item => [0, 1, 5].includes(item.id)))
							// this.tabList = this.tabList.slice(0, 1)
							break;
						case 12:
						case 14:
						case 18:
							bottomList = array.filter(item => [0, 1, 10].includes(item.id))
							if (this.tabList.length < 2) {
								this.tabList.push({
									name: '同局来友',
									count: 0
								})
							}
							break;
						case 13:
							bottomList = array.filter(item => (this.status == 10 ? [0, 1, 7].includes(item.id) : [0, 1, 9]
								.includes(item.id)))
							// this.tabList = this.tabList.slice(0, 1)
							break;
						case 15:
							bottomList = array.filter(item => (item.status == 10 ? [0, 1, 6].includes(item.id) : [0, 1, 7]
								.includes(item.id)))
							// this.tabList = this.tabList.slice(0, 1)
							break;
						case 16:
							bottomList = array.filter(item => [0, 1, 6].includes(item.id))
							if (this.tabList.length < 2) {
								this.tabList.push({
									name: '同局来友',
									count: 0
								})
							}
							break;
						case 17:
						case 19:
							bottomList = array.filter(item => [0, 1, 6].includes(item.id))
							// this.tabList = this.tabList.slice(0, 1)
							break;
					}
				}
				this.bottomList = bottomList
				if (this.tabList.length > 1) {
					this.tabList.find(item => item.name == '同局来友').count = this.teaData.un_apply
				}
			},
			dealSwiperBanner(list, type) {
				if (list) {
					let imageList = list.split(',')
					imageList.map(item => {
						const params = {
							url: item,
							type: type,
							id: generateUUID()
						}
						this.bannerList.push(params)
					})
				} else {
					return
				}
			},
			swiperChange(val) {
				let index = val.detail.current
				this.bannerTypeList.map(item => {
					if (item.type == this.bannerList[index].type) {
						item.check = true
					} else {
						item.check = false
					}
				})
			},
			handleClick(methodName) {
				/* 通用点击方法 */
				if (this.momentJudge()) {
					this[methodName]?.()
				}
			},
			openSwiper(index) {
				/* swiper图片预览 */
				let previewList = []
				this.bannerList.map(item => previewList.push(item.url))
				uni.previewImage({
					current: index,
					urls: previewList
				})
			},
			clickSwiper(val) {
				/* swiper模块切换 */
				if (!val.check) {
					for (let i = 0; i < this.bannerList.length; i++) {
						if (this.bannerList[i].type == val.type) {
							this.swiperCurrent = i
							return
						}
					}
					this.bannerTypeList.map(typeItem => typeItem.check = false)
					val.check = true
				}
			},
			getTeaPersonList() {
				/* 来友列表 */
				const params = {
					user_id: this.user_id,
					tea_id: this.tea_id
				}
				teaFriend(params).then(res => {
					this.teaFriendList.length = 0
					res.data.tea_friend.map(item => this.teaFriendList.push(item))
				})
			},
			goTeaPersonDetail(val) {
				uni.navigateTo({
					url: "/teaBureau/teaPersonDetail/teaPersonDetail?id=" + val
				})
			},
			previewPoster(val) {
				/* 图片预览 */
				switch (val) {
					case 1:
						this.poster.image = this.poster.signImage
						break;
					case 2:
						this.poster.image = this.teaData.info.weixin_url
						break;
					case 3:
						this.poster.image = this.teaData.image
						break;
				}
				this.poster.show = true
			},
			getCheckInQrCode() {
				/* 打开签到码 */
				if (this.poster.signImage) {
					return
				} else {
					teaSignCode({
						tea_id: this.tea_id
					}).then(res => {
						this.poster.signImage = res.data.sign_url
					})
				}
			},
			closeShare() {
				this.shareShow = false
			},
			openMoment() {
				if (this.moment.image) {
					this.moment.show = true
				} else {
					uni.showLoading({
						title: "加载中"
					})
					const params = {
						tea_id: this.tea_id,
						user_id: uni.getStorageSync("user_id")
					}
					teaQrcode(params).then(res => {
						uni.hideLoading()
						this.moment.image = res.data.url
						this.moment.show = true
					})
				}
			},
			modalConfirm() {
				const _this = this
				if (this.user_status == "0") {
					uni.navigateTo({
						url: "/pages/register/register"
					})
				} else {
					/* 交换好友 */
					if (this.isExchange) {
						userInfo({
							user_id: this.user_id
						}).then(res => {
							let integral = res.data.integral // 用户积分
							const params = {
								key: "ExchangeCards",
								type: 0
							}
							singleIntegral(params).then(singleRes => {
								let singleIntegral = singleRes.data.value
								if (parseInt(integral) < parseInt(singleIntegral)) {
									uni.showToast({
										title: "积分不足",
										icon: "none"
									})
								} else {
									this.isExchange = false
									const applyParams = {
										user_id: this.user_id,
										from_user_id: this.teaData.user.id
									}
									businessCardApply(applyParams).then(applyRes => {
										uni.showToast({
											title: `${applyRes.msg}`,
											icon: "none"
										})
									})
								}
							})
						})
					}
					/* 结束酒局 */
					if (this.isFinish) {
						if (this.finishType == 44) {
							this.modal.show = false
						} else {
							const params = {
								user_id: this.user_id,
								tea_id: this.tea_id,
								type: this.finishType
							}
							this.isFinish = false
							teaEnd(params).then(res => {
								setTimeout(()=>{
									this.getTeaDetail()
									this.modal.show = false
								},1000)
								getApp().globalData.switchCustom = true
							})
						}
					}
					/* 报名活动 */
					if (this.isPlay) {
						const params = {
							user_id: this.user_id,
							tea_id: this.tea_id,
							reference_id: this.inviterId
						}
						this.isPlay = false
						teaPlay(params).then(res => {
							this.modal.show = false
							this.modal.content =
								`${this.teaData.info.is_apply == 1 ? '请等待青创私董审核' : '报名成功（如遇取消请联系青创私董）'}`
							this.modal.confirm = '确定'
							this.modal.show = true
							this.getTeaDetail()
						})
					}
					/* 付费报名 */
					if (this.isPay) {
						this.isPay = false
						this.onTeaPay()
					}
					/* 评价酒局 */
					if (this.isScore) {
						this.isScore = false
						const params = {
							id: this.tea_id,
							type: this.isPromoter ? 1 : 2
						}
						uni.navigateTo({
							url: "/teaBureau/teaExamine/teaExamine?data=" + JSON.stringify(params)
						})
					}
					/* 审核报名 */
					if (this.isExamine) {
						const params = {
							// user_id: this.examine.user_id,
							user_id: this.user_id,
							apply_id: this.examine.apply_id,
							is_examine: 1
						}
						this.isExamine = false
						teaApply(params).then(res => {
							uni.showToast({
								title: `${res.msg}`,
								icon: "none",
								duration: "3000"
							})
							this.getTeaDetail()
							this.getTeaPersonList()
						})
					}
					/* 用户已通过青创私董审核取消报名 */
					if (this.isProcess) {
						const params = {
							user_id: this.user_id,
							id: this.examine.apply_id || '',
							type: 1
						}
						this.isProcess = false
						teaRefuse(params).then(res => {
							uni.showToast({
								title: `${res.msg}`,
								icon: "none",
								duration: "3000"
							})
							this.getTeaDetail()
							this.getTeaPersonList()
						})
					}
					/* 取消报名 */
					if (this.isRefuse) {
						const params = {
							user_id: this.user_id,
							id: this.refuse.apply_id || '',
							tea_id: this.tea_id,
							type: this.refuse.apply_id ? 1 : 2
						}
						this.isRefuse = false
						teaRefuse(params).then(res => {
							uni.showToast({
								title: "操作成功",
								icon: "none"
							})
							this.getTeaDetail()
							this.getTeaPersonList()
						})
					}
					/* 上传合照 */
					if (this.isUpload) {
						uni.navigateTo({
							url: "/teaBureau/teaGroupPhoto/teaGroupPhoto?id=" + this.tea_id
						})
						this.isUpload = false
					}
					/* 待审核取消报名 */
					if (this.isAuditRefuse) {
						const params = {
							user_id: this.user_id,
							tea_id: this.tea_id,
							type: 1
						}
						this.isAuditRefuse = false
						teaAuditRefuse(params).then(res => {
							uni.showToast({
								title: "操作成功",
								icon: "none"
							})
							this.getTeaDetail()
						})
					}
				}
				this.modal.show = false
				this.modal.cancel = '取消'
				this.modal.confirm = '确定'
			},
			modalCancel() {
				this.isExchange = false
				this.isPlay = false
				this.isPay = false
				this.isScore = false
				this.isFinish = false
				this.isRefuse = false
				this.isAuditRefuse = false
				if (this.isExamine) {
					this.isExamine = false
					const params = {
						// user_id: this.examine.user_id,
						user_id: this.user_id,
						apply_id: this.examine.apply_id,
						is_examine: 2
					}
					teaApply(params).then(res => {
						uni.showToast({
							title: `${res.msg}`,
							icon: "none",
							duration: "3000"
						})
						this.isExamine = false
						this.modal.cancel = '取消'
						this.modal.show = false
						this.getTeaPersonList()
					})
				} else if (this.isProcess) {
					this.isProcess = false
					const params = {
						user_id: this.user_id,
						id: this.examine.apply_id || '',
						type: 2
					}
					teaRefuse(params).then(res => {
						uni.showToast({
							title: `${res.msg}`,
							icon: "none",
							duration: "3000"
						})
						this.modal.cancel = '取消'
						this.modal.show = false
						this.getTeaPersonList()
					})
				} else {
					this.modal.show = false
				}
			},
			addPerson() {
				/* 添加好友 */
				if (this.momentJudge()) {
					/* const params = {
						key: "ExchangeCards",
						type: 0
					}
					singleIntegral(params).then(res => {
						this.modal.content = `交换名片需要消耗${res.data.value}积分，请问是否仍要继续？`
						this.modal.show = true
						this.isExchange = true
					}) */
					this.modal.content = `交换名片，对方同意后交换成功`
					this.modal.show = true
					this.isExchange = true
				}
			},
			async chooseThank() {
				/* 打开感谢框 */
				const res = await giftList()
				res.data.map(item => {
					item.check = false
				})
				res.data.push({
					id: 9527,
					name: '自定义积分',
					num: '',
					check: false
				})
				this.gift.list = res.data
				this.giftShow = true
			},
			async onGiftChoose(val) {
				if (val.checkNum) {
					this.giftBtnStatus = false
					const params = {
						user_id: this.teaData.user.id,
						give_user_id: this.user_id,
						num: val.checkNum,
						content: val.text,
						is_anonymous: val.isAnonymous ? 1 : 2
					}
					const res = await userGiveGift(params)
					this.getTeaDetail()
					this.gift.checkId = 0
					this.gift.checkNum = 0
					this.gift.text = ''
					this.gift.isAnonymous = true
					this.giftBtnStatus = true
					this.giftShow = false
					uni.showToast({
						title: "提交成功",
						icon: "none"
					})
					uni.navigateTo({
						url: "/teaBureau/teaThanksList/teaThanksList?id=" + this.teaData.user.id
					})
				} else {
					uni.showToast({
						title: "请选择积分",
						icon: "none"
					})
				}
			},
			onGiftClose() {
				this.giftBtnStatus = true
				this.giftShow = false
			},
			switchThanksList() {
				uni.navigateTo({
					url: "/teaBureau/teaThanksList/teaThanksList?id=" + this.teaData.user.id
				})
			},
			async viewDonateImage() {
				const res = await getConfigInfo({
					key: 'donate'
				})
				this.donateData.url = res.data.value
				this.donateData.show = true
			},
			getExamine(val) {
				/* 点击审核 */
				if (this.momentJudge()) {
					this.modal.content = '请选择是否审核通过'
					this.modal.confirm = '通过'
					this.modal.cancel = '拒绝'
					this.modal.show = true
					this.isExamine = true
					this.examine = val
				}
			},
			getProcess(val) {
				/* 点击审核已通过用户 */
				if (this.momentJudge()) {
					this.modal.content = '来友申请取消报名，请审核'
					this.modal.confirm = '同意'
					this.modal.cancel = '取消'
					this.modal.show = true
					this.isProcess = true
					this.examine = val
				}
			},
			getRefuse(val) {
				/* 点击取消 */
				if (this.momentJudge()) {
					this.modal.content = '是否确定取消？'
					this.modal.confirm = '确定'
					this.modal.cancel = '取消'
					this.modal.show = true
					this.isRefuse = true
					this.refuse = val
				}
			},
			share() {
				/* 分享酒局 */
				if (this.momentJudge()) {
					this.shareShow = true
				}
			},
			signIn() {
				/* 签到 */
				if (this.momentJudge()) {
					uni.showLoading({
						title: "正在加载中"
					})
					if (this.poster.image) {
						uni.hideLoading()
						this.poster.show = true
					} else {
						teaSignCode({
							tea_id: this.tea_id
						}).then(res => {
							this.poster.image = res.data.sign_url
							this.poster.show = true
							uni.hideLoading()
						})
					}
				}
			},
			finish() {
				/* 结束酒局 */
				if (this.momentJudge()) {
					if (this.teaData.info.tea_status == 5) {
						uni.showToast({
							title: "该酒局已经结束",
							icon: "none"
						})
					} else {
						// // 判断是否有合照
						// if(this.teaData.images){
						// 	let teaStartTime = new Date(this.teaData.info.start_time.replace(/-/g, "/")).getTime()
						// 	let nowTime = new Date().getTime()
						// 	if (nowTime < teaStartTime) {
						// 		this.modal.content = '当前酒局尚未开始，若提前结束酒局将<span class="u-color-red">失效</span>，并<span class="u-color-red">退款</span>。请确定是否仍要结束？'
						// 		this.finishType = 11
						// 	} else {
						// 		const params = {
						// 			user_id: this.user_id,
						// 			tea_id: this.tea_id
						// 		}
						// 		teaFriend(params).then(res => {
						// 			let signNumber = 0
						// 			res.data.tea_friend.map(item => {
						// 				if (item.is_examine == 1) signNumber++
						// 			})
						// 			if (signNumber < Number(this.teaData.info.min_people)) {
						// 				this.finishType = 22
						// 				this.modal.content =
						// 					'当前酒局<span class="u-color-red">报名人数不符合</span>酒局要求，结束后酒局将<span class="u-color-red">失效</span>并<span class="u-color-red">退款</span>，请确定是否仍要结束？'
						// 			} else {
						// 				this.finishType = 0
						// 				this.modal.content = '是否结束酒局'
						// 			}
						// 		})
						// 	}
						// }else{
						// 	this.finishType = 44
						// 	this.modal.content = '合照未上传，不可结束'
						// }
						let teaStartTime = new Date(this.teaData.info.start_time.replace(/-/g, "/")).getTime()
						let nowTime = new Date().getTime()
						if (nowTime < teaStartTime) {
							this.modal.content =
								'当前酒局尚未开始，若提前结束酒局将<span class="u-color-red">失效</span>，请确定是否仍要结束？'
							this.finishType = 11
						} else {
							const params = {
								user_id: this.user_id,
								tea_id: this.tea_id
							}
							teaFriend(params).then(res => {
								let signNumber = 0
								res.data.tea_friend.map(item => {
									if (item.is_examine == 1) signNumber++
								})
								if (signNumber < Number(this.teaData.info.min_people)) {
									this.finishType = 22
									this.modal.content =
										'当前酒局<span class="u-color-red">报名人数不符合</span>酒局要求，结束后酒局将<span class="u-color-red">失效</span>，请确定是否仍要结束？'
								} else {
									this.finishType = 0
									this.modal.content = '是否结束酒局'
								}
							})
						}
						this.modal.confirm = '确定'
						this.modal.show = true
						this.isFinish = true
					}
				}
			},
			assess() {
				/* 评价 */
				if (this.momentJudge()) {
					const params = {
						id: this.tea_id,
						type: this.isPromoter ? 1 : 2
					}
					uni.navigateTo({
						url: "/teaBureau/teaExamine/teaExamine?data=" + JSON.stringify(params)
					})
				}
			},
			signUp() {
				/* 立即报名 */
				if (this.momentJudge()) {
					if (this.user_status == "0") {
						this.modal.content = '部分功能需注册解锁，注册后即可体验完整服务'
						this.modal.confirm = '前往注册'
						this.modal.show = true
					} else {
						if (this.teaData.info.pay_type == 2) {
							this.modal.content =
								`当前为付费酒局，费用为青创私董线下收取，报名后若无法参与请提前取消，截止${this.teaData.info.deadline_time.slice(0,16)} 前可取消，否则需青创私董审核`
							this.modal.confirm = '确定'
							this.modal.show = true
							this.isPay = true
						} else {
							// this.modal.content = '是否确定报名'
							this.modal.content =
								`当前为付费酒局，费用为青创私董线下收取，报名后若无法参与请提前取消，截止${this.teaData.info.deadline_time.slice(0,16)} 前可取消，否则需青创私董审核`
							this.modal.confirm = '确定'
							this.modal.show = true
							this.isPlay = true
						}
					}
				}
			},
			async withdraw() {
				/* 商家转账 */
				// const res = await teaWithdraw({
				// 	tea_id: this.tea_id
				// })
				// switch(res.data.state){
				// 	case 'WAIT_USER_CONFIRM':
				// 	case 'TRANSFERING':
				// 	    if (wx.canIUse('requestMerchantTransfer')) {
				// 	    	wx.requestMerchantTransfer({
				// 	    		mchId: res.data.mchid,
				// 	    		appId: res.data.appid,
				// 	    		package: res.data.package_info,
				// 	    		success: (res) => {
				// 					_this.getTeaDetail()
				// 				},
				// 	    		fail: (res) => {},
				// 	    	});
				// 	    } else {
				// 	    	wx.showModal({
				// 	    		content: '你的微信版本过低，请更新至最新版本。',
				// 	    		showCancel: false,
				// 	    	});
				// 	    }
				// 		break;
				// 	case 'ACCEPTED':
				// 	    this.modal.content = '转账已受理'
				// 		this.modal.confirm = '确定'
				// 		this.modal.show = true
				// 		break;
				// 	case 'PROCESSING':
				// 	    this.modal.content = '转账锁定资金中。如果一直停留在该状态，建议检查账户余额是否足够，如余额不足，可充值后再原单重试'
				// 		this.modal.confirm = '确定'
				// 		this.modal.show = true
				// 		break;
				// 	case 'SUCCESS':
				// 	    this.modal.content = '转账成功'
				// 		this.modal.confirm = '确定'
				// 		this.modal.show = true
				// 		break;
				// 	case 'FAIL':
				// 	    this.modal.content = '转账失败'
				// 		this.modal.confirm = '确定'
				// 		this.modal.show = true
				// 		break;
				// 	case 'CANCELING':
				// 	    this.modal.content = '商户撤销请求受理成功，该笔转账正在撤销中'
				// 		this.modal.confirm = '确定'
				// 		this.modal.show = true
				// 		break;
				// 	case 'CANCELLED':
				// 	    this.modal.content = '转账撤销完成'
				// 		this.modal.confirm = '确定'
				// 		this.modal.show = true
				// 		break;
				// }
				uni.navigateTo({
					url: "/teaBureau/teaDrawList/teaDrawList?tea_id=" + this.tea_id
				})
			},
			mission() {
				/* 任务 */
				uni.navigateTo({
					url: "/teaBureau/teaMission/teaMission?id=" + this.tea_id
				})
			},
			onBack() {
				/* 返回 */
				let pages = getCurrentPages()
				let prePage = pages[pages.length - 2]
				if (prePage) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: "/pages/home/home"
					})
				}
			},
			toUseTool(val) {
				/* 工具栏点击 */
				if (this.momentJudge()) {
					switch (val) {
						case 1:
							call(this.teaData.user.phone)
							break;
						case 2:
							uni.openLocation({
								latitude: Number(this.teaData.info.latitude),
								longitude: Number(this.teaData.info.longitude),
							})
							break;
						case 3:
							uni.navigateTo({
								url: "/operate/feedback/feedback?id=" + this.tea_id + '&type=2'
							})
							break;
						case 4:
							if (!this.isPromoter && this.teaData.is_sign == 1) {
								this.modal.content = '您已签到，不可取消'
								this.modal.confirm = '确定'
								this.modal.cancel = '取消'
								this.modal.show = true
							} else {
								switch (this.teaData.info.user_status) {
									/* 11 已通过  12 待审核  */
									case 11:
									case 12:
										const params = {
											user_id: this.user_id,
											tea_id: this.tea_id
										}
										teaAuditRefuse(params).then(res => {
											switch (res.err) {
												case "-43":
													this.modal.content = '是否确认取消？'
													this.modal.confirm = '确定'
													this.modal.cancel = '取消'
													this.modal.show = true
													if (this.teaData.info.user_status == 11) {
														this.isRefuse = true
														this.refuse = {}
													} else {
														this.isAuditRefuse = true
													}
													break;
												case "-42":
													this.getTeaDetail()
													break;
												case "-41":
													let now = new Date().getTime()
													let deal = new Date(this.teaData.info.deadline_time).getTime()
													if (now > deal) {
														this.modal.content = '当前报名已审核通过，取消报名需要青创私董审核，是否仍要取消？'
													} else {
														this.modal.content = '是否确认取消？'
													}
													this.modal.confirm = '确认取消'
													this.modal.cancel = '暂不取消'
													this.modal.show = true
													if (this.teaData.info.user_status == 11) {
														this.isRefuse = true
														this.refuse = {}
													} else {
														this.isAuditRefuse = true
													}
													this.refuse = {}
													break;
											}
										})
										break;
									default:
										this.modal.content = '频繁取消将影响您的失约记录，是否仍要取消？'
										this.modal.confirm = '确定'
										this.modal.cancel = '取消'
										this.modal.show = true
										this.isRefuse = true
										this.refuse = {}
										break;
								}
							}
							break;
					}
				}
			},
			modeClose() {
				this.modal.show = false
				this.isExchange = false
				this.isPlay = false
				this.isExamine = false
				this.isScore = false
				this.isFinish = false
			},
			callMobile(val) {
				call(val)
			},
			openTool(num) {
				/* 青创私董工具栏 */
				if (this.momentJudge()) {
					switch (num) {
						case 1:
						case 2:
							this.video.url = ''
							this.video.time = 0
							this.video.url = this.toolList.filter(item => item.id == num)[0].url
							this.video.time = this.toolList.filter(item => item.id == num)[0].time
							this.video.show = true
							break;
						case 3:
							uni.navigateTo({
								url: "/teaBureau/teaBankList/teaBankList?id=" + this.tea_id
							})
							break;
						case 4:
							uni.navigateTo({
								url: "/teaBureau/teaMission/teaMission?id=" + this.tea_id
							})
							break;
						case 5:
							teaCheckSign({
								tea_id: this.tea_id
							}).then(res => {
								if (res.data.is_have > 0) {
									const params = {
										id: this.tea_id,
										type: this.isPromoter ? 1 : 2
									}
									uni.navigateTo({
										url: "/teaBureau/teaExamine/teaExamine?data=" + JSON.stringify(
											params)
									})
								} else {
									uni.showToast({
										title: "当前未有签到记录，无法使用该功能",
										icon: "none"
									})
								}
							})
							break;
						case 6:
							const params = {
								image: this.teaData.image ? this.teaData.image : this.teaData.images,
								id: this.tea_id,
								teaStatus: this.tea_status
							}
							uni.navigateTo({
								url: "/teaBureau/teaGroupPhoto/teaGroupPhoto?data=" + JSON.stringify(params)
							})
							break;
						case 7:
							uni.navigateTo({
								url: "/operate/agreement/agreement?type=21"
							})
							break;
					}
				}
			},
			async onTeaPay() {
				/* 酒局付费报名 */
				const orderSnRes = await teaOrderSn()
				const params = {
					order_sn: orderSnRes.data.order_sn,
					type: "tea",
					userid: this.user_id,
					id: this.tea_id,
					reference_id: this.inviterId
				}
				const creRes = await teaCreateOrder(params)
				const _this = this
				await uni.requestPayment({
					provider: "wxpay",
					appId: creRes.data.order_str.appId,
					timeStamp: creRes.data.order_str.timeStamp,
					nonceStr: creRes.data.order_str.nonceStr,
					package: creRes.data.order_str.package,
					signType: creRes.data.order_str.signType,
					paySign: creRes.data.order_str.paySign,
					success() {
						_this.modal.content =
							`${_this.teaData.info.is_apply == 1 ? '请等待青创私董审核' : '报名成功（如遇取消请联系青创私董）'}`
						_this.modal.confirm = '确定'
						_this.modal.show = true
						_this.getTeaDetail()
					},
					fail(err) {
						uni.hideLoading()
						uni.showLoading({
							title: err,
						})
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			momentJudge() {
				if (!uni.getStorageSync("user_id")) {
					uni.showToast({
						icon: "none",
						duration: 2000,
						title: "请先点击下方'前往小程序'方可对接",
					})
					return false
				} else {
					if (uni.getStorageSync("user_isBlack") == 0) {
						return true
					} else {
						this.modal.content = '当前用户权限受限，请联系系统管理员'
						this.modal.confirmText = '确定'
						this.modal.show = true
						return false
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-badge-mini {
		top: 16rpx !important;
		right: 100rpx !important;
	}

	.swiper_box {
		height: 350rpx;
		background: #fff;
		border-radius: 20rpx;
	}

	.swiper_type_box {
		position: absolute;
		bottom: 30rpx;
		display: flex;
		left: 40rpx;
		background: #fff;
		border-radius: 30rpx;
		font-size: 25rpx;

		.swiper_type {
			padding: 10rpx 20rpx;
		}

		.check {
			background-color: #B3723E;
			color: #fff;
			border-radius: 30rpx;
			transition: all 0.3s;
		}
	}

	.twice_box {
		width: 100%;
		height: 80rpx;
		display: flex;
		justify-content: space-between;

		.share {
			width: 46%;
			background: #F96257;
			color: #fff;
			height: 100%;
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.right {
			width: 46%;
			background: #999;
			color: #fff;
			height: 100%;
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.bottom_btn {
		text-align: center;
		padding: 24rpx 0;
		color: #fff;
		border-radius: 50rpx;
	}

	.bottom_btn_box {
		width: 100%;
		display: flex;
		justify-content: space-between;
	}
</style>